<template>
  <div class="answers_subscript" style="display: none;">
    <div :class="['answers_subscript_favorite', favorite ? 'answers_favorite' : '']" @click="addFavorite">
      <van-icon name="star-o" size="22"/>
    </div>
  </div>
</template>

<script>
import API from '@/api/api-chat-list.js'
export default {
  name: "AnswersSubscript",
  props: ['answersData'],
  data() {
    return {
      favorite: false
    }
  },
  created() {
    this.favorite = this.answersData.data.favorite;
  },
  methods: {
      async addFavorite() {
        const data = this.answersData.data;
        const favoriteData = await API.addFavorite({
          esQuestionId: data.id,
          category: data.category,
          type: this.favorite ? 0 : 1
        });
        if (favoriteData.result === "1") {
          this.favorite = !this.favorite;
          this.$toast.success(`${this.favorite ? "收藏" : "取消收藏"}成功`)

      }
    }
  }
}
</script>

<style scoped>
@import url('~@/assets/css/home/answersSubscript.css');
</style>
